<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>微信签到-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart style="background: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"> <a href="<%=basePath %>/ls" class="icon icon-109 f-white">返回</a> </div>
	    	<h1 class="weui-header-title">微信签到</h1>
	    </div>
		<div class="weui_tab_bd">
	        <div class="weui_cells" style="margin-top: 0;">
	        	<div class="weui_cell card_sign_box f-15">
	        		<p>说明：只能在校内教学区WIFI覆盖范围内签到，如教师办公室。<span class="f-white">${ip }</span></p>
	        	</div>
	        </div>
	        
	        <div class="weui_cells afterNone afterNoneBefore mt0">
	        	<div class="weui_cell card_sign_box f-15">
	        		<h3 class="f-green">上班签到时间说明</h3><br/><br/>
	        	</div>
	        	<div style="padding: 0 10px;">
					<ul>
					    <li>上午签到（6:00-8:00）<br/><br/></li>
					    <li>下午签到（13:50-15:00）</li>		
					</ul>
				</div>
	        </div>
	        
       		<div class="weui_cells tm afterNone afterNoneBefore hide" id="isSchool">
	        	<input type="hidden" id="ip"/>
	        	<p id="signResult" class="pb15 hide"></p>
	        	<p id="signSubmit" class="weui_btn weui_btn_primary w33">签到</p>
	        </div>
       		<div class="weui_cells tm afterNone afterNoneBefore hide" id="noSchool">
       			<p class="pb15 tm f-red">请在校内教学区WIFI覆盖范围内签到</p>
       		</div>
       		
	        <div class="weui_cells afterNone afterNoneBefore signDay hide">
	        	<div class="pl15 pr10 f-green">今日签到记录</div>
	        	<div id="todayList" class="card_sign_box"></div>
	        </div>
	        <div class="weui_cells afterNone afterNoneBefore signDay">
	        	<a class="pl15 pr10" style="text-decoration: underline;" href="<%=basePath%>/common/work/signTotal">一周签到记录</a>
	        </div>
	    </div>
<script type="text/javascript">
	$(function() {
		var ip = "${ip}";
		//if(ip && (ip.indexOf("10.21.156") != -1 || ip.indexOf("10.21.157") != -1 || 
		//		ip.indexOf("10.21.158") != -1 || ip.indexOf("10.21.159") != -1)) {
		if(true){	
			$("#isSchool").show();
			$("#ip").val(ip);
			signSubmit();
		}else {
			$("#noSchool").show();
		}
		today();
	})
	function signSubmit() {
		var obj = $("#signSubmit");
		$.ajax({
	   		url: basePath + "/common/work/cardSign/submit",
	   		type: 'POST',
	   		dataType : "json",
	   		data: {
	   			ip: $("#ip").val()
	   		},
	   		success: function(data) {
	   			if(data.code == '000') {
	   				$("#signResult").html('<i class="weui_icon_success"></i><span class="f-green">  签到成功！</span>').show();
	   				today();
	   			}else{
	   				$("#signResult").html('<i class="f-red weui_icon_warn"></i><span class="f-red">  '+data.msg+'</span>').show();
	   			}
				obj.remove();
	   		},
	   		error: function(data) {
	   		}
		});
	}
	function today() {
		$.ajax({
	   		url: basePath + "/common/work/today",
	   		type: 'POST',
	   		dataType : "json",
	   		success: function(data) {
	   			if(data != null && data.length > 0) {
	   				$(".signDay").show();
	   				var html = '';
	   				for(var i in data) {
	   					var itm = data[i];
	   					html+='<div class="weui_cell">\
						          	<div class="weui_cell_hd">\
				          		<label class="weui_label">'+(itm.signType == 1 ? '上午' : '下午')+'</label>\
				          	</div>\
			         		<div class="weui_cell_bd weui_cell_primary">'+getTime(itm.signTime,'yyyy-MM-dd hh:mm')+'</div></div>';
	   				}
	   				$("#todayList").html(html);
	   			}
 	   		},
	   		error: function(data) {
	   		}
		});
	}
	
</script>
</body>
</html>